//
//  HBViewController.m
//  HBLibary
//
//  Created by Rambo on 06/03/2018.
//  Copyright (c) 2018 Rambo. All rights reserved.
//

#import "HBViewController.h"
#import <HBLibary/HBLibary.h>
#import "HBDemoModel.h"


@interface HBViewController ()<UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) HBDataSource *dataSource;

@end

@implementation HBViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.navigationItem.title = @"HBLibary";
    
    HBDemoModel *emptyTableViewDemo = [[HBDemoModel alloc] initWithTitle:@"UITableView空视图" clsName:@"HBEmptyTableViewController"];
    
    HBDemoModel *textViewDemo = [[HBDemoModel alloc] initWithTitle:@"textViewDemo" clsName:@"HBTextViewController"];
    
    HBDemoModel *tagLayoutDemo = [[HBDemoModel alloc] initWithTitle:@"tagWaterLayout" clsName:@"HBTagWaterLayoutViewController"];
    
    HBDemoModel *pageSegmentDemo = [[HBDemoModel alloc] initWithTitle:@"pagesegmentVC" clsName:@"HBPageSegmentDemoViewController"];
    
    HBDemoModel *labelDemo = [[HBDemoModel alloc] initWithTitle:@"copyLabel" clsName:@"HBLabelDemoViewController"];
    
    HBDemoModel *categoryDemo = [[HBDemoModel alloc] initWithTitle:@"分类" clsName:@"HBCategoryViewController"];
    
    HBDemoModel *guideDemo = [[HBDemoModel alloc] initWithTitle:@"引导图" clsName:@"HBLaunchGuideViewController"];
    
    HBDemoModel *stringListDemo = [[HBDemoModel alloc] initWithTitle:@"标签列表" clsName:@"HBStringListViewController"];
    
    HBDemoModel *badgeDemo = [[HBDemoModel alloc] initWithTitle:@"角标" clsName:@"HBBadgeViewController"];
    
    HBDemoModel *moneyDemo = [[HBDemoModel alloc] initWithTitle:@"金额输入框" clsName:@"HBMoneyTextFiledViewController"];
    
    HBDemoModel *videoFirstFrame = [[HBDemoModel alloc] initWithTitle:@"视频第一帧图片" clsName:@"HBVideoFirstFrameViewController"];
    
    HBDemoModel *protocolDispatcher = [[HBDemoModel alloc] initWithTitle:@"代理分发器" clsName:@"HBProtocolDispatcherViewController"];
    
    HBDemoModel *dateChoose = [[HBDemoModel alloc] initWithTitle:@"时间选择器" clsName:@"HBDateChooseViewController"];
    
    
    NSArray *datas = @[emptyTableViewDemo, textViewDemo, tagLayoutDemo, pageSegmentDemo, labelDemo, categoryDemo, guideDemo, stringListDemo, badgeDemo, moneyDemo, videoFirstFrame, protocolDispatcher, dateChoose];
    
    
    static NSString *cellId = @"cellId";
    
    self.dataSource = [[HBDataSource alloc] initWithIdentifier:cellId tableViewDataSource:^(UITableViewCell *cell, HBDemoModel *model, NSIndexPath *indexPath) {
        cell.textLabel.text = model.title;
    }];
    
    [self.dataSource addModels:datas];
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    tableView.dataSource = self.dataSource;
    tableView.delegate = self;
    tableView.tableFooterView = [UIView new];
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellId];
    [self.view addSubview:tableView];
//    self.count = 0;
//    HBScrollEmptyView *emptyView = [HBScrollEmptyView emptyWithImage:[UIImage imageNamed:@"icon_network_error"] title:@"暂无数据" detail:nil target:self action:@selector(loadMore)];
//    HBScrollEmptyView *emptyView = [HBScrollEmptyView emptyWithImage:[UIImage imageNamed:@"icon_network_error"] title:@"暂无数据" detail:nil emptyViewTapBlock:^{
//        self.count = 20;
//        [self.tableView reloadData];
//    }];
    
//    HBScrollEmptyView *emptyView = [HBScrollEmptyView emptyWithImage:[UIImage imageNamed:@"icon_network_error"] title:@"暂无数据" detail:nil buttonTitle:@"点击重试" target:self action:@selector(loadMore)];
//    HBScrollEmptyView *emptyView = [HBScrollEmptyView emptyWithImage:[UIImage imageNamed:@"icon_network_error"] title:@"网络异常" detail:nil buttonTitle:@"点击重试" buttonActionTapBlock:^{
//        self.count = 20;
//        [self.tableView reloadData];
//    }];
//    emptyView.buttonBackgroundColor = [UIColor redColor];
//    tableView.hb_emptyView = emptyView;
//    self.tableView = tableView;
    
    
//    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
//    textView.placeholder = @"哈哈哈";
//    textView.font = [UIFont systemFontOfSize:12];
//    [self.view addSubview:textView];
}

//- (void)loadMore{
//    self.count = 20;
//    [self.tableView reloadData];
//}
//
//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//    return self.count;
//}
//
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//    static NSString *cellId = @"cell";
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
//    if (!cell) {
//        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
//    }
//    cell.textLabel.text = [NSString stringWithFormat:@"标题%zd",indexPath.row];
//
//    return cell;
//}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    HBDemoModel *model = [self.dataSource getModelWithIndexPath:indexPath];
    if (!model) return;
    UIViewController *vc = [[NSClassFromString(model.clsName) alloc] init];
    if (!vc) return;
    [self.navigationController pushViewController:vc animated:YES];
}

@end
